#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QSignalMapper>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    setWindowFlags(Qt::FramelessWindowHint | windowFlags());
    QLayout* layout = this->layout();
    layout->setContentsMargins(0, 0, 0, 0);

    ui->btn_group->setParent(this);

    managerSignals();

    ui->stackedWidget->setCurrentWidget(ui->myfile_page);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::showMainWindow()
{
    m_common.moveToCenter(this);
    ui->myfile_page->refreshFiles();
}

void MainWindow::managerSignals()
{
    connect(ui->btn_group, &buttongroup::sigMyFile, [=]()
    {
        ui->stackedWidget->setCurrentWidget(ui->myfile_page);
        ui->myfile_page->refreshFiles();
    });

    connect(ui->btn_group, &buttongroup::sigShareList, [=]()
    {
        ui->stackedWidget->setCurrentWidget(ui->sharelist_page);
        ui->sharelist_page->refreshFiles();
    });

    connect(ui->btn_group, &buttongroup::sigSwitchUser, [=]()
    {
        cout << "切换用户";
        loginAgain();
    });

    connect(ui->btn_group, &buttongroup::sigTransform, [=]()
    {
        ui->stackedWidget->setCurrentWidget(ui->transfer_page);
    });

    connect(ui->btn_group, &buttongroup::sigDownload, [=]()
    {
        ui->stackedWidget->setCurrentWidget(ui->rankinglist_page);
    });
}

void MainWindow::loginAgain()
{
    emit changeUser();
    ui->myfile_page->clearAllTask();
}
